package com.yikaiye.android.yikaiye.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Window;
import android.view.WindowManager;

import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.yikaiye.android.yikaiye.R;


public abstract class BaseCommonBottomDialog<T extends ViewDataBinding> extends Dialog {
    protected T mBinding;
    protected Context mContext;

    public BaseCommonBottomDialog(Context context) {
        super(context, R.style.prompt_progress_dialog_dimenabled);
        this.mContext = context;
    }

    @Override
    protected void onStart() {
        super.onStart();
        setWidth(WindowManager.LayoutParams.MATCH_PARENT);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding = DataBindingUtil.inflate(LayoutInflater.from(getContext()), getLayoutId(), null, false);
        setContentView(mBinding.getRoot());
        Window window = getWindow();
        if (window != null) {
            window.setGravity(getGravity());
            window.setWindowAnimations(getAnimations());
            initView();
        }
    }

    public void setWidth(int width) {
        Window window = getWindow();
        if (window != null) {
            WindowManager.LayoutParams lp = window.getAttributes();
            // x/y坐标
            // lp.x = 100;
            // lp.y = 100;
            lp.width = width;
            window.setAttributes(lp);
        }
    }

    protected int getAnimations() {
        return R.style.main_menu_animStyle;
    }

    protected int getGravity() {
        return Gravity.BOTTOM;
    }

    protected abstract void initView();

    protected abstract int getLayoutId();

    @Override
    protected void onStop() {
        super.onStop();
    }
}
